package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.OperateFunctionGetPageDTO;
import com.itlong.cloud.POJO.PO.OperateFunctionPO;
import com.itlong.cloud.POJO.VO.operate.OperateAllotFunctionGetVO;
import com.itlong.cloud.POJO.VO.operate.OperateFunctionVO;
import com.itlong.cloud.POJO.VO.operate.OperateGetRoleMenuVO;
import com.itlong.cloud.operate.service.IOperateFunctionService;
import com.itlong.cloud.user.operate.IOperateFunctionServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * <desc>
 *      运营-资源菜单业务处理暴露接口实现类
 * </desc>
 *
 * @createDate 2017/09/21
 */
@RestController
public class OperateFunctionServiceResource implements IOperateFunctionServiceClient{
    @Autowired
    IOperateFunctionService iOperateFunctionService;

    /**
     * <desc>
     *      获取分页列表
     * </desc>
     *
     * @param operateFunctionGetPageDTO 分页查询参数DTO
     * @return 分页模型
     * @author Jiaqi.X
     * @createDate 2017/09/21
     */
    @Override
    @RequestMapping(path = "/operate/system/function/getPage")
    public Page<OperateFunctionPO> getPage(@RequestBody OperateFunctionGetPageDTO operateFunctionGetPageDTO) throws Exception {
        return iOperateFunctionService.getPage(operateFunctionGetPageDTO);
    }

    /**
     * <desc>
     *      添加资源
     * </desc>
     * @param operateFunctionPO 资源实体
     * @return sql执行行数
     * @author Jiaqi.X
     * @createDate 2017/09/21
     */
    @Override
    @RequestMapping(path = "/operate/system/function/save")
    public Integer save(@RequestBody OperateFunctionPO operateFunctionPO) throws Exception {
        return iOperateFunctionService.save(operateFunctionPO);
    }

    /**
     * <desc>
     *      修改资源
     * </desc>
     * @param operateFunctionPO 资源实体
     * @return sql执行行数
     * @author Jiaqi.X
     * @createDate 2017/09/21
     */
    @Override
    @RequestMapping(path = "/operate/system/function/update")
    public Integer update(@RequestBody OperateFunctionPO operateFunctionPO) throws Exception {
        return iOperateFunctionService.update(operateFunctionPO);
    }

    /**
     * <desc>
     *      查询单条资源
     * </desc>
     *
     * @param operateFunctionPO 资源实体
     * @return 资源实体
     * @author Jiaqi.X
     * @createDate 2017/09/21
     */
    @Override
    @RequestMapping(path = "/operate/system/function/getOne")
    public OperateFunctionPO getOne(@RequestBody OperateFunctionPO operateFunctionPO) {
        return iOperateFunctionService.getOne(operateFunctionPO);
    }

    /**
     * <desc>
     *      删除资源
     * </desc>
     *
     * @param functionIds 资源id数组
     * @return 执行行数
     * @author Jiaqi.X
     * @createDate 2017/09/21
     */
    @Override
    @RequestMapping(path = "/operate/system/function/delete")
    public Integer delete(@RequestParam("functionIds") String functionIds) {
        return iOperateFunctionService.delete(functionIds);
    }

    /**
     * <desc>
     *      获取子节点
     * </desc>
     *
     * @param functionId 资源id
     * @return 子级结果集
     * @author Jiaqi.X
     * @craeteDate 2017/09/21
     */
    @Override
    @RequestMapping(path = "/operate/system/function/getChilds")
    public List<OperateFunctionVO> getChilds(@RequestParam(" ")String functionId) {
        return iOperateFunctionService.getChilds(functionId);
    }

    /**
     * <desc>
     *      获取分配菜单所有节点
     * </desc>
     *
     * @return
     * @author Jiaqi.X
     * @createDate 2017/09/26
     */
    @Override
    @RequestMapping(path = "/operate/system/function/getAllotFunction")
    public List<OperateAllotFunctionGetVO> getAllotFunction(@RequestParam("roleId") String roleId) {
        return iOperateFunctionService.getAllotFunction(roleId);
    }

    /**
     * <desc>
     *      获取当前节点的父级节点以及同级别所有父级节点
     * </desc>
     *
     * @param parent 资源id
     * @return
     * @author Jiaqi.X
     * @createDate 2017/09/30
     */
    @Override
    public List<OperateFunctionPO> getParentLevelFunctions(@RequestParam("parent") String parent) {
        return iOperateFunctionService.getParentLevelFunctions(parent);
    }

    @Override
    public List<OperateGetRoleMenuVO> getAuthBtns(@RequestParam("roleIds") String roleIds, @RequestParam("functionId") String functionId) {
        return iOperateFunctionService.getAuthBtns(roleIds,functionId);
    }

    @Override
    public List<OperateGetRoleMenuVO> getRoleMenu(@RequestParam("roleIds") String roleIds) {
        return iOperateFunctionService.getRoleMenu(roleIds);
    }

    @Override
    public List<OperateFunctionPO> getRoleAuthFunctions(@RequestParam("roleIds") String roleIds, @RequestParam("token") String token) throws IOException {
        return iOperateFunctionService.getRoleAuthFunctions(roleIds,token);
    }
}
